package com.app.screen;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * Created by IntelliJ IDEA.
 * User: Murilo Dourado Souza
 * Date: 12/2/11
 * Time: 11:56 AM
 */
public class ScreenShoot {
    /**
     * This Class provide the sevice to have screen shoots from the screen
     */
   public static void getScreenShoot(String type) {
        try{
            Long waitingTime = 4 * 1000L;
            //This will wait for 6 minutes
            //Long waitingTime = Long.parseLong("360") * 1000L;
            //Print the waiting time
            System.out.println("Waiting time for next screen shoot " + (waitingTime / 1000L) + " seconds");
            int counterName = 0;
            Boolean fn = (type == "Play")? true : false;
            while(fn){
                Toolkit toolkit = Toolkit.getDefaultToolkit();
                Dimension screenSize = toolkit.getScreenSize();
                //This is to get the screen shot image
                // Resolution set for 1280X1024
                //BufferedImage bi = rb.createScreenCapture(new Rectangle(0,0,1280,1024));
                Robot rb = new Robot();
                counterName++;
                String fileName = "screen_shoot"+counterName;
                BufferedImage bi = rb.createScreenCapture(new Rectangle(screenSize));
                //Save image
                ImageIO.write(bi, "jpg", new File(fileName+".jpg"));
                System.out.println("Screen shoot "+fileName+ " saved");
                try {
                    Thread.sleep(waitingTime);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        } catch (AWTException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }
}